package cn.bluedot.framework.util;

import java.util.regex.Pattern;

/**
 * 字符串工具类
 * @author Administrator
 *
 */
public class StringUtils {
		
	/**
	 * 判空
	 * @param obj
	 * @return
	 */
	public static boolean isEmpty(Object obj) {
		return obj == null || "".equals(obj);
	}
	
	/**
	 * 非空
	 * @param obj
	 * @return
	 */
	public static boolean isNotEmpty(Object obj) {
		return obj != null || !"".equals(obj);
	}
	
	/**
	 * 正则表达式匹配
	 * @param str
	 * @param pattern 
	 * @return
	 */
	public static boolean matches(String str, String pattern) {
        if (isEmpty(str)) {
            return false;
        }
        return Pattern.matches(pattern, str);
    }
	
	/**
	 * 正则表达式匹配: 数字
	 * @param str
	 * @return
	 */
	public static boolean isNumber(String str) {
		String pattern = "^[0-9]*$";
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: n位数字
	 * @param n
	 * @param str
	 * @return
	 */
	public static boolean isNumber(int n, String str) {
		String pattern = "^\\d{"+n+",}$";
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: m~n位数字
	 * @param m
	 * @param n
	 * @param str
	 * @return
	 */
	public static boolean isNumber(int m, int n, String str) {
		String pattern = "^\\d{"+m+","+n+"}$";		
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: 汉字
	 * @param str
	 * @return
	 */
	public static boolean isCharacter(String str){
		String pattern = "^[\\u4e00-\\u9fa5]{0,}$";
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: 字母组合
	 * @param str
	 * @return
	 */
	public static boolean isLetter(String str){
		String pattern = "^[A-Za-z]+$";
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: 字母数字下划线组合
	 * @param str
	 * @return
	 */
	public static boolean isNumberLetterLine(String str){
		String pattern = "^\\w+$";
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: 邮箱
	 * @param str
	 * @return
	 */
	public static boolean isEmail(String str){
		String pattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: 手机号码
	 * @param str
	 * @return
	 */
	public static boolean isPhoneNumber(String str){
		String pattern = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
		return Pattern.matches(pattern , str);
	}
	
	/**
	 * 正则表达式匹配: 国内电话号码
	 * @param str
	 * @return
	 */
	public static boolean isPhone(String str){
		String pattern = "\\d{3}-\\d{8}|\\d{4}-\\d{7}";
		return Pattern.matches(pattern , str);
	}
	

}
